package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class Substraction extends CalculationExpression {
	public Substraction(E e1, E e2){
		super(e1,e2);
	}

	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		try{
			if(getExpression1().getContent(map, givenCollisionObject).getClass() == Double.class 
					&& getExpression2().getContent(map, givenCollisionObject).getClass() == Double.class){
				double content =(double)getExpression1().getContent(map, givenCollisionObject) - (double)getExpression2().getContent(map, givenCollisionObject);
				return content;
			}
			System.out.println("There was a mistake in the given program, please correct it.");
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			return null;
		}
		catch(NullPointerException exc){
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			return null;}
	}
}